<?php
include('../config.php');
include(PUNG_ROOT . '/admin/header.php');

$adminmenu = array(
LANG_091 => 'blocks.php',
LANG_092 => 'addblock.php'
);

if(isset($_POST['submit']))
{
	$sql = $db -> db_query("SELECT * FROM " . DB_PREFIX . "blocks ORDER BY position ASC");
	$sql = $db -> db_result();
	
	foreach($sql as $block)
	{
		$db -> db_query("UPDATE " . DB_PREFIX . "blocks SET 
		position = '" . $_POST['position' . $block['id']] . "',
		height = '" . $_POST['height' . $block['id']] . "',
		visible = '" . $_POST['visible' . $block['id']] . "' 
		WHERE id = '" . $block['id'] . "'");
	}
	
	redirect_with_message('msg', 'LANG_110');
}

if(isset($_GET['delete']))
{
	if(is_numeric($_GET['delete']))
	{
		$db -> db_query("DELETE FROM " . DB_PREFIX . "blocks 
		WHERE id = '" . $_GET['delete'] . "'");
		
		redirect_with_message('msg', 'LANG_111');
	}
}

include(PUNG_ROOT . '/admin/head.php');
?>

<h3><?php print LANG_093; ?></h3>

<?php
$sql = $db -> db_query("SELECT * FROM " . DB_PREFIX . "blocks ORDER BY position ASC");
$sql = $db -> db_result();
?>

<form action="" method="post">
<table width="100%">
<tr>
	<th><?php print LANG_095; ?></th>
	<th><?php print LANG_096; ?></th>
	<th><?php print LANG_097; ?></th>
	<th><?php print LANG_098; ?></th>
	<th>&nbsp;</th>
</tr>
<?php foreach($sql as $block) { ?>
<tr>
	<td><?php print $block['title']; ?></td>
	<td width="70">
	<select name="position<?php print $block['id']; ?>">
	<option value="left"<?php if($block['position'] == 'left'){print ' selected="selected"';} ?>><?php print LANG_099; ?></option>
	<option value="right"<?php if($block['position'] == 'right'){print ' selected="selected"';} ?>><?php print LANG_100; ?></option>
	</select>
	</td>
	<td width="50">
	<select name="height<?php print $block['id']; ?>">
	<option value="0"<?php if($block['height'] == '0'){print ' selected="selected"';} ?>>0</option>
	<option value="1"<?php if($block['height'] == '1'){print ' selected="selected"';} ?>>1</option>
	<option value="2"<?php if($block['height'] == '2'){print ' selected="selected"';} ?>>2</option>
	<option value="3"<?php if($block['height'] == '3'){print ' selected="selected"';} ?>>3</option>
	<option value="4"<?php if($block['height'] == '4'){print ' selected="selected"';} ?>>4</option>
	<option value="5"<?php if($block['height'] == '5'){print ' selected="selected"';} ?>>5</option>
	<option value="6"<?php if($block['height'] == '6'){print ' selected="selected"';} ?>>6</option>
	</select>
	</td>
	<td width="60">
	<select name="visible<?php print $block['id']; ?>">
	<option value="yes"<?php if($block['visible'] == 'yes'){print ' selected="selected"';} ?>><?php print LANG_101; ?></option>
	<option value="no"<?php if($block['visible'] == 'no'){print ' selected="selected"';} ?>><?php print LANG_102; ?></option>
	</select>
	</td>
	<td align="center" width="70">
	<a href="editblock.php?id=<?php print $block['id']; ?>" title="<?php print LANG_103; ?>"><img 
	src="<?php print PUNG_URL . '/images/admin_img/edit.png'; ?>" alt="" /></a>
	
	<a  href="#" onClick="confirm_box('<?php print LANG_126; ?>', '?delete=<?php print $block['id']; ?>');" title="<?php print LANG_104; ?>"><img 
	src="<?php print PUNG_URL . '/images/admin_img/uninstall.png'; ?>" alt="" /></a>
	</td>
</tr>
<?php } ?>
</table>
<br />
<input type="submit" value="<?php print LANG_105; ?>" name="submit" class="form_button" />
</form>

<?php
include(PUNG_ROOT . '/admin/footer.php');
?>